<?php

class Model_BlogCategory extends Model {

    function __construct() {
        
    }

    function getCategoryByReport($h_param = array()) {
        $rid = $h_param['rid'];
        if (!$rid)
            return array();
        $where = "rid=" . $rid;

        $param = array();
        $param['field'] = "";
        $param['where'] = $where;
        $param['order'] = "";
        $param['group'] = "";
        $param['limit'] = "";
        $param['pagesize'] = 999;
        $param['page'] = 1;
        $param['join'] = "";
        $param['on'] = "";
        $data = db_query_hash('blog_otm_category', $param);


        if ($data['result']) {
            $result = $data['result'];
        }

        return $result;
    }

    function getList($h_param = array()) {
        $mid = $h_param['mid'];

        if (!$mid)
            return array();
        $topid = $h_param['topid'] ? $h_param['topid'] : 0;

        $result = $this->getCategory(array('mid' => $mid, 'topid' => $topid));

        if ($result) {
            $childs = array();
            foreach ($result as $value) {
                if ($value['topid'] == $topid)
                    $childs[$value['id']] = array(
                        'name' => $value['name'],
                        'sub_category' => $this->getList(array('mid' => $mid, 'topid' => $value['id']))
                    );
            }
        }
        return $childs;
    }

    function getCategory($h_param = array()) {
        $mid = $h_param['mid'];

        if (!$mid)
            return array();
        $topid = $h_param['topid'] ? $h_param['topid'] : 0;


        $where = "mid=" . $mid . " and topid=" . $topid;
        $result = array();
        $param = array();
        $param['field'] = "";
        $param['where'] = $where;
        $param['order'] = "id asc";
        $param['group'] = "";
        $param['limit'] = "";
        $param['pagesize'] = 999;
        $param['page'] = 1;
        $param['join'] = "";
        $param['on'] = "";
        $data = db_query_hash('blog_category', $param);


        if ($data['result']) {
            $result = $data['result'];
        }

        return $result;
    }

}

?>